package cn.iocoder.yudao.module.study.message.service;

import cn.iocoder.yudao.module.study.message.factory.MessageHandleFactory;
import cn.iocoder.yudao.module.study.message.handle.ISendMsgService;
import cn.iocoder.yudao.module.study.message.vo.MsgVO;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author cjc
 * @Date 2024/3/19 16:00
 * @Description: 消息服务实现类
 * @Version 1.0
 */
@Service
@Slf4j
public class MsgServiceImpl implements MsgService {

    @Override
    public void sendMsg(JSONObject msg) {
        //模拟消息类型
        String[] msgType = new String[]{"1","2","3","4","5","6","7","7","8"};

        // 根据类型发送消息
        for (String type : msgType) {
            try {
                ISendMsgService sendMsgHandle = MessageHandleFactory.getMsgHandle(type);
                MsgVO msgVO = new MsgVO();
                msgVO.setBusinessType("order");
                msgVO.setOperateType("publish");
                sendMsgHandle.sendMsg(msgVO);
            } catch (Exception e) {
                log.error("MsgServiceImpl-sendMsg,type:{},data:{},error:{}", type, msg.toJSONString(), e.getMessage());
            } finally {
                log.info("--------------------------------------");
            }

        }

    }

}
